﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CJJCH.Web
{
    public partial class Index1 : System.Web.UI.Page
    {
        CJJCH.BLL.T_INF_News bll_BookNews = new BLL.T_INF_News();
        CJJCH.BLL.T_NET_Standards bll_Standards = new BLL.T_NET_Standards();
        CJJCH.BLL.T_NET_News bll_news = new BLL.T_NET_News();
        CJJCH.BLL.T_NET_PicNews bll_picnews = new BLL.T_NET_PicNews();
        public string strPic, strLink, strText;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ReapterDataBinding();
            }
        }
        private void ReapterDataBinding()
        {

            #region 绑定图片新闻

            DataSet ds = null;
            string PicUploadPath = LTP.Common.ConfigHelper.GetConfigString("UploadPic").Replace("~/", "");
            ds = bll_picnews.GetPicNews();
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (!dr["PicUrl"].ToString().Contains("://"))
                    {
                        strPic += dr["PicUrl"].ToString().Replace("~/","") + "|";
                    }
                    else
                    {
                        strPic += dr["PicUrl"].ToString() + "|";
                    }
                    strLink += dr["HrefUrl"].ToString() + "|";
                    if (dr["Instructions"].ToString().Length > 10)
                    {
                        strText += dr["Instructions"].ToString().Substring(0, 10) + "…|";
                    }
                    else
                    {
                        strText += dr["Instructions"].ToString() + "|";
                    }
                }
            }

            strPic = string.IsNullOrEmpty(strPic) ? "" : strPic.Remove(strPic.Length - 1, 1).ToString();
            strLink = string.IsNullOrEmpty(strLink) ? "" : strLink.Remove(strLink.Length - 1, 1).ToString();
            strText = string.IsNullOrEmpty(strText) ? "" : strText.Remove(strText.Length - 1, 1).ToString();
            #endregion


            DataSet dss = new DataSet();
            dss = bll_news.GetListAgo();

            //通知公告绑定
            this.rptNotice.DataSource = dss.Tables[4].DefaultView;
            this.rptNotice.DataBind();

            //协会要问绑定
            this.rptAssNews.DataSource = dss.Tables[5].DefaultView;
            this.rptAssNews.DataBind();

            //政策法规绑定
            this.rptPolReg.DataSource = dss.Tables[6].DefaultView;
            this.rptPolReg.DataBind();

            //行业要闻绑定
            this.rptIndustryNews.DataSource = dss.Tables[7].DefaultView;
            this.rptIndustryNews.DataBind();

            //政府部门友情链接绑定
            this.dropGovDep.DataSource = dss.Tables[17].DefaultView;
            this.dropGovDep.DataValueField = "URLString";
            this.dropGovDep.DataTextField = "URLName";
            this.dropGovDep.DataBind();
            this.dropGovDep.Items.Insert(0, new ListItem("政府部门", "0"));

            //北京市政府友情链接绑定
            this.dropbjGov.DataSource = dss.Tables[18].DefaultView;
            this.dropbjGov.DataValueField = "URLString";
            this.dropbjGov.DataTextField = "URLName";
            this.dropbjGov.DataBind();
            this.dropbjGov.Items.Insert(0, new ListItem("北京市政府", "0"));

            //合作单位友情链接绑定
            this.dropCooperationUnit.DataSource = dss.Tables[19].DefaultView;
            this.dropCooperationUnit.DataValueField = "URLString";
            this.dropCooperationUnit.DataTextField = "URLName";
            this.dropCooperationUnit.DataBind();
            this.dropCooperationUnit.Items.Insert(0, new ListItem("合作单位", "0"));

            //其他部门友情链接绑定
            this.dropOtherDep.DataSource = dss.Tables[20].DefaultView;
            this.dropOtherDep.DataValueField = "URLString";
            this.dropOtherDep.DataTextField = "URLName";
            this.dropOtherDep.DataBind();
            this.dropOtherDep.Items.Insert(0, new ListItem("其他部门", "0"));

            //前两个友情链接绑定
            this.rptUr1l.DataSource = dss.Tables[21].DefaultView;
            this.rptUr1l.DataBind();

            //后两个友情链接绑定
            this.rptUr2l.DataSource = dss.Tables[22].DefaultView;
            this.rptUr2l.DataBind();
            
        }
        /// <summary>
        /// 通知公告绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptNotice_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((Label)e.Item.FindControl("lblPlusDate")).Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PlusDate").ToString()).ToString("yyyy/MM/dd");
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).Text = LTP.Common.StringClass.GetENString(DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString(), 14);
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).ToolTip = DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString();
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).NavigateUrl = "" + LTP.Common.StringClass.EncodeUrl(DataBinder.Eval(e.Item.DataItem, "ID").ToString());
                
            }
        }

        /// <summary>
        /// 协会要问绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptAssNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                ((Label)e.Item.FindControl("lblPlusDate")).Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PlusDate").ToString()).ToString("yyyy/MM/dd");
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).Text = LTP.Common.StringClass.GetENString(DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString(), 14);
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).ToolTip = DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString();
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).NavigateUrl = "" + LTP.Common.StringClass.EncodeUrl(DataBinder.Eval(e.Item.DataItem, "ID").ToString());
                
            }
        }

        /// <summary>
        /// 政策法规绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptPolReg_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                ((Label)e.Item.FindControl("lblPlusDate")).Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PlusDate").ToString()).ToString("yyyy/MM/dd");
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).Text = LTP.Common.StringClass.GetENString(DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString(), 14);
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).ToolTip = DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString();
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).NavigateUrl = "" + LTP.Common.StringClass.EncodeUrl(DataBinder.Eval(e.Item.DataItem, "ID").ToString());
                
            }
        }

        /// <summary>
        /// 行业要闻绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptIndustryNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                ((Label)e.Item.FindControl("lblPlusDate")).Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PlusDate").ToString()).ToString("yyyy/MM/dd");
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).Text = LTP.Common.StringClass.GetENString(DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString(), 14);
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).ToolTip = DataBinder.Eval(e.Item.DataItem, "DataTitle").ToString();
                ((HyperLink)e.Item.FindControl("lnkDataTitle")).NavigateUrl = "" + LTP.Common.StringClass.EncodeUrl(DataBinder.Eval(e.Item.DataItem, "ID").ToString());
                
            }
        }
        
        /// <summary>
        /// 前两个友情链接绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptUr1l_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((ImageButton)e.Item.FindControl("ibtnUrl")).ImageUrl = DataBinder.Eval(e.Item.DataItem, "PicUrl").ToString();
                ((ImageButton)e.Item.FindControl("ibtnUrl")).PostBackUrl = DataBinder.Eval(e.Item.DataItem, "URLString").ToString();
                ((HyperLink)e.Item.FindControl("lnkUrl")).Text = DataBinder.Eval(e.Item.DataItem, "URLName").ToString();
                ((HyperLink)e.Item.FindControl("lnkUrl")).NavigateUrl = DataBinder.Eval(e.Item.DataItem, "URLString").ToString();
            }
        }
        /// <summary>
        /// 后两个友情链接绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptUr2l_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((ImageButton)e.Item.FindControl("ibtnUrl")).ImageUrl = DataBinder.Eval(e.Item.DataItem, "PicUrl").ToString();
                ((ImageButton)e.Item.FindControl("ibtnUrl")).PostBackUrl = DataBinder.Eval(e.Item.DataItem, "URLString").ToString();
                ((HyperLink)e.Item.FindControl("lnkUrl")).Text = DataBinder.Eval(e.Item.DataItem, "URLName").ToString();
                ((HyperLink)e.Item.FindControl("lnkUrl")).NavigateUrl = DataBinder.Eval(e.Item.DataItem, "URLString").ToString();
            }
        }








        protected void rptBookNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
        }
    }
}